/**
 * 培训通知列表
 */
<template>
	<vp-main-page @refresh="loadDataList" :tableRef="tableRef">
		<template #search>
			<el-form ref="searchFormRef" :model="searchForm" @submit.prevent @keyup.enter="loadDataList" label-width="120px">
				<vp-search-row :show-more="showMore">
					<vp-search-col>
						<el-form-item prop="bh">
							<template #label><vp-label zh="课程编号" en="Course No."/></template>
							<el-input v-model="searchForm.bh" v-trim clearable></el-input>
						</el-form-item>
					</vp-search-col>
					<vp-search-col>
						<el-form-item prop="mc">
							<template #label><vp-label zh="课程名称" en="Course Name"/></template>
							<el-input v-model="searchForm.mc" v-trim clearable></el-input>
						</el-form-item>
					</vp-search-col>
					<vp-search-col btn-col>
						<vp-btn-search :loading="loading" @click="loadDataList"/>
						<vp-btn-reset @click="handleSearchReset"/>
						<vp-btn-more @change="showMore = $event" />
					</vp-search-col>
				</vp-search-row>
			</el-form>
		</template>
		<template #table>
			<vp-vxe-table
				id="trainingExtStudyTable"
				ref="tableRef" 
				:data="tableData" 
				@sort-change="handleSortChange" 
				row-key="id"
				v-loading="loading"
			>	
				<vxe-column type="seq" align="center" title="#" width="50" />
				<vxe-column 
					sortable
					field="kcbh" 
					title="课程编号 Course No."
					show-overflow
					width="120"
				>
					<template #header><vp-label zh="课程编号" en="Course No."/></template>
					<template #default="{ row }">
						<el-link @click="handleViewCourse(row.id)">{{ row.bh }}</el-link>
					</template>
				</vxe-column>
				<vxe-column 
					field="kcmc_zw" 
					title="课程名称 Course Name"
					show-overflow 
					min-width="200"
				>
					<template #header><vp-label zh="课程名称" en="Course Name" /></template>
					<template #default="{ row }">
						<span>{{ (row.mcZw || '') + ' ' + (row.mcYw || '') }}</span>
					</template>
				</vxe-column>
				<vxe-column 
					field="acTypes" 
					title="适用机型 A/C Type"
					show-overflow 
					:min-width="100"
				>
					<template #header><vp-label zh="适用机型" en="A/C Type"/></template>
					<template #default="scope">
						<span v-for="(item, index) in scope.row.acTypes" :key="index">
							<el-tag> {{ item.jx }} </el-tag>&nbsp;
						</span>
					</template>
				</vxe-column>
				<vxe-column 
					field="kclb" 
					title="课程类别 Course Category"
					show-overflow 
					:min-width="120"
				>
					<template #header><vp-label zh="课程类别" en="Course Category"/></template>
				</vxe-column>
				<vxe-column 
					field="operation" 
					title="操作 Operation"
					fixed="right" 
					width="140"
				>
					<template #header><vp-label-operations/></template>
					<template #default="{ row }">
						<el-space>
							<vp-btn type="primary" text @click="handleOnlineLearning(row)">
								<vp-label zh="学习" en="Learning" />
							</vp-btn>
						</el-space>
					</template>
				</vxe-column>
			</vp-vxe-table>
		</template>
		<template #pagination>
			<vp-pagination
				@change="loadDataList"
				:total="page.total" 
				v-model:currentPage="page.pageNum"
				v-model:pageSize="page.pageSize"
			>
			</vp-pagination>
		</template>
		<VpOnlineLearning ref="vpOnlineLearningRef" @formSubmited="loadDataList"></VpOnlineLearning>
	</vp-main-page>
</template>
<script setup lang="ts" name="trainingExtStudy">
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue'
import request from '/@/utils/request';
import { useRouter } from 'vue-router';
import { DEFAULT_PAGE } from '/@/utils/page';

const VpOnlineLearning = defineAsyncComponent(() => import('/@/components/vp/learning/VpOnlineLearning.vue'));

const searchForm = reactive({
	bh: "",
	mc: "",
	zxbs: 2,
	kzxxbs: 10,
	ztList:[89]
});

const page = reactive({
	...DEFAULT_PAGE,
})

const showMore = ref(false);
const loading = ref(false);
const tableData = ref([]);

const router = useRouter();

// 加载列表数据
const loadDataList = () => {
	loading.value = true;
	request.get('/training/course/pageList', {
		params: {
			...searchForm,
			...page,
		}
	}).then(res => {
		tableData.value = res?.data?.list || [];
		page.total = res?.data?.total || 0;
		page.pageNum = res?.data?.pageNum || 1;
	}).finally(()=>{
		loading.value = false;
	})
}

const searchFormRef = ref();
// 重置搜索条件
const handleSearchReset = ()=>{
	searchFormRef.value.resetFields();
}

// 列表字段排序
const handleSortChange = (column: any)=>{
	page.sortColumn = column.field;
	page.sortOrder = column.order;
	loadDataList()
}

onMounted(() => {
	loadDataList();
})

const tableRef = ref();

// 查看课程
const handleViewCourse = (id: string)=>{
	router.push({
		name: "viewTrainingCourse",
		params: {
			id: id,
		},
	})
}

// 在线学习
const vpOnlineLearningRef = ref();
const handleOnlineLearning = (row: any) => {
	vpOnlineLearningRef.value.handleOpen({
		courseId: row.id,	// 课程id
		trainingRecordId: ''	// 培训记录id（实参id）
	});
}

</script>

<style scoped lang="scss">
</style>